package com.ktgj.hotel.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.hotel.domain.HotelOrderInvoice;
import com.ktgj.hotel.service.IHotelOrderInvoiceService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 酒店订单发票Controller
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@ControllerAdvice
@RestController
@RequestMapping("/invoice")
public class HotelOrderInvoiceController extends BaseController
{
    @Autowired
    private IHotelOrderInvoiceService hotelOrderInvoiceService;

    /**
     * 查询酒店订单发票列表
     */
    @PreAuthorize(hasPermi = "hotel:invoice:list")
    @GetMapping("/list")
    public TableDataInfo list(HotelOrderInvoice hotelOrderInvoice)
    {
        startPage();
        List<HotelOrderInvoice> list = hotelOrderInvoiceService.selectHotelOrderInvoiceList(hotelOrderInvoice);
        return getDataTable(list);
    }

    /**
     * 导出酒店订单发票列表
     */
    @PreAuthorize(hasPermi = "hotel:invoice:export")
    @Log(title = "酒店订单发票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HotelOrderInvoice hotelOrderInvoice) throws IOException
    {
        List<HotelOrderInvoice> list = hotelOrderInvoiceService.selectHotelOrderInvoiceList(hotelOrderInvoice);
        ExcelUtil<HotelOrderInvoice> util = new ExcelUtil<HotelOrderInvoice>(HotelOrderInvoice.class);
        util.exportExcel(response, list, "酒店订单发票数据");
    }

    /**
     * 获取酒店订单发票详细信息
     */
    @PreAuthorize(hasPermi = "hotel:invoice:query")
    @GetMapping(value = "/{invoiceid}")
    public AjaxResult getInfo(@PathVariable("invoiceid") Long invoiceid)
    {
        return AjaxResult.success(hotelOrderInvoiceService.selectHotelOrderInvoiceById(invoiceid));
    }

    /**
     * 新增酒店订单发票
     */
    @PreAuthorize(hasPermi = "hotel:invoice:add")
    @Log(title = "酒店订单发票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HotelOrderInvoice hotelOrderInvoice)
    {
        return toAjax(hotelOrderInvoiceService.insertHotelOrderInvoice(hotelOrderInvoice));
    }

    /**
     * 修改酒店订单发票
     */
    @PreAuthorize(hasPermi = "hotel:invoice:edit")
    @Log(title = "酒店订单发票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HotelOrderInvoice hotelOrderInvoice)
    {
        return toAjax(hotelOrderInvoiceService.updateHotelOrderInvoice(hotelOrderInvoice));
    }

    /**
     * 删除酒店订单发票
     */
    @PreAuthorize(hasPermi = "hotel:invoice:remove")
    @Log(title = "酒店订单发票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{invoiceids}")
    public AjaxResult remove(@PathVariable Long[] invoiceids)
    {
        return toAjax(hotelOrderInvoiceService.deleteHotelOrderInvoiceByIds(invoiceids));
    }

    /**
     * 新增酒店订单发票
     */
    @PostMapping("/addHotelOrderInvoice")
    public AjaxResult addHotelOrderInvoice(@RequestBody HotelOrderInvoice hotelOrderInvoice) {
        if (hotelOrderInvoice != null){
            int i = hotelOrderInvoiceService.addHotelOrderInvoice(hotelOrderInvoice);
            if (i > 0){
                return AjaxResult.success("成功");
            }
            else {
                return AjaxResult.error("失败");
            }
        }
        else {
            return AjaxResult.error("缺少必要参数");
        }
    }
}
